package com.example.controller;

import com.example.common.AppResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 * Description:测试API接口注解
 * User: bjc
 * Date: 2025-09-04
 * Time: 14:25
 */
@RestController
//@RequestMapping("/api")
//@Tag(name = "测试API生成相关接口", description = "演示 Knife4j + springdoc 的自动文档")
public class HelloController {

//    @GetMapping("/hello")
    @Operation(summary = "测试接口1，用来显示hello", description = "返回 Hello 字符串")
    //@RequestParam作用：用来在文档界面中显示参数
    public String hello(@RequestParam(required = false) String name) {
        return "Hello, " + (name == null ? "World" : name);
    }

//    @GetMapping("/exception")
    @Operation(summary = "测试接口2，用来抛出异常", description = "抛出一个异常")
    public AppResult testException() throws Exception{
        throw new Exception("这是一个Exception");
    }
//    @PostMapping("/helloByName")
//    @Operation(summary = "测试接口3，通过参数获取用户名", description = "按照传入的参数显示输出内容")
    public String helloByName(@Parameter(description = "用户名")@RequestParam("name") String  name){
        return "Hello, " + name;
    }

}
